<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script language="javascript" src="funcoes.js"></script>

<fieldset>
    <legend>
        Pesquisa pelo Paciente
    </legend> 
    <form action="Controller?action=BuscaAgenda" method="POST">
        Nome: <input type="text" name="cpNomePaciente" value="" />  
        <input type="submit" name="btn" value="Pesquisar por paciente" /> <br />
    </form>   
</fieldset>
<fieldset>
    <legend>
        Pesquisa pelo Dentista
    </legend> 
    <form action="Controller?action=BuscaAgenda" method="POST">
        Nome: <input type="text" name="cpNomeDentista" value="" />  
        <input type="submit" name="btn" value="Pesquisar por dentista" /> <br />
    </form>   
</fieldset>
<fieldset>
    <legend>
        Pesquisa pela data de Agendamento
    </legend> 
    <form action="Controller?action=BuscaAgenda" method="POST">
        <table>
            <tr>
            <input type="hidden" name="idProfissional" value="${sessionScope.profissional.idProfissional}" />
            <td>Data: <input type="text" name="cpData" value="" maxlength="10" onkeypress="formata_mascara(this, '##/##/####'); return Numero(event);"/></td>
            <td><input type="submit" name="btn" value="Pesquisar por data"/></td>
            </tr>
        </table>
    </form> 
</fieldset> 

<table border="1" style= "width: 100%">
    <thead style="background: black; color: white">
        <tr>
            <th>ID</th>
            <th>Data/Horario</th>
            <th>Paciente</th>
            <th>Dentista</th>
            <th>Atendente</th>
            <th>Cancelar</th>
            <th>Alterar</th>     
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${requestScope.ListaAgenda}" var="ag">    
            <tr>                
                <th>${ag.idAgenda}</th>
                <th><f:formatDate value="${ag.data}" pattern="dd/MM/yyyy HH:mm"/></th>

                <c:forEach items="${requestScope.ListaPaciente}" var="pac"> 
                    <c:if test="${pac.idPaciente == ag.paciente.idPaciente}">
                        <th>${pac.nome}</th>
                    </c:if>
                </c:forEach>
                <c:forEach items="${requestScope.ListaProfissional}" var="prof">
                    <c:if test="${prof.idProfissional == ag.dentista.idProfissional}">
                        <th>${prof.nome}</th>
                    </c:if>
                </c:forEach>          
                <c:forEach items="${requestScope.ListaProfissional}" var="prof">
                    <c:if test="${prof.idProfissional == ag.atendente.idProfissional}">
                        <th>${prof.nome}</th>
                    </c:if>
                </c:forEach> 

                <td><a href="Controller?action=ApagaAgenda&idAgenda=${ag.idAgenda}">Cancelar</a></td>
                <td><a href="Controller?action=AlteraAgenda&idAgenda=${ag.idAgenda}">Alterar</a></td>

            </tr>
        </c:forEach>
    </tbody>    
</table>

<h3 style="color: red">${requestScope.msg}</h3>

<form method="POST" action="Controller?action=NovaAgenda">
    <input type="submit" value="Novo" />
</form>
